﻿using System;

namespace Collatz
{
    /// <summary>
    /// 表示解决特定问题的类
    /// </summary>
    public abstract class Solver
    {
        /// <summary>
        /// 用指定的最大数值创建一个实例
        /// </summary>
        /// <param name="start">最大数值，从此数值开始向递减方向解算</param>
        /// <exception cref="ArgumentOutOfRangeException">当<paramref name="start"/>不是正整数时引发</exception>
        public Solver(int start)
        {
            if (start <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(start), start, CollatzSerial.StartMustBeAPositiveInteger);
            }
            _start = start;
        }

        /// <summary>
        /// 最大数值，从此数值开始向递减方向解算
        /// </summary>
        protected readonly int _start;

        /// <summary>
        /// 获取用于解算的最大数值
        /// </summary>
        public int Start => _start;

        /// <summary>
        /// 从<see cref="Start"/>开始依次递减，解算最长序列
        /// </summary>
        /// <returns>最长序列的开始数值</returns>
        public abstract int Solve();
    }
}
